const express = require("express");
const cors = require("cors");
const pools = require("./pool.js");

const user = require("./routes/user.js"); //用户路由
const commodity = require("./routes/commodity.js"); //商品路由
const fenlei = require("./routes/fenlei.js"); //分类路由
const address = require("./routes/address.js"); //地址路由
const ping = require("./routes/ping.js"); //评价路由
const order = require("./routes/order.js"); //订单路由
const cart = require("./routes/cart.js"); //购物车路由
const enshrine = require("./routes/enshrine.js"); //收藏路由
const feedback = require("./routes/feedback.js"); //反馈路由
const banner = require("./routes/banner.js"); //轮播图路由
const multer = require("./others/multer.js"); //文件上传路由
const qiandao = require("./routes/qiandao.js");//签到



const app = express();
//配置跨域
app.use(
  cors({
    origin: "*", //指定接收的地址
    methods: ["GET", "POST", "DELETE", "PUT"], //指定接收的请求类型
    alloweHeaders: ["Content-Type", "Authorization"], //指定header
  })
);

//托管静态文件
app.use(express.static("public"));
app.listen(3000, () => {
  console.log("服务器启动成功");
});

//将所有post传递的参数转为对象
app.use(
  express.urlencoded({
    extended: true,
  })
);

app.use("/user", user);
app.use("/commodity", commodity);
app.use("/fenlei", fenlei);
app.use("/address", address);
app.use("/ping", ping);
app.use("/order", order);
app.use("/cart", cart);
app.use("/enshrine", enshrine);
app.use("/feedback", feedback);
app.use("/banner", banner);
app.use("/multer", multer);
app.use("/qiandao", qiandao);//签到


app.use((err, req, res, next) => {
  if (err) {
    console.log(err);
  }
  res.send({ code: 502, msg: "服务器端错误" });
});
